{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Create plot of the SLA L4 product."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import glob\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from mpl_toolkits.basemap import Basemap\n",
    "from matplotlib import rcParams\n",
    "import netCDF4\n",
    "import logging\n",
    "import divaaltimetry\n",
    "import warnings\n",
    "import matplotlib.cbook\n",
    "warnings.filterwarnings(\"ignore\",category=matplotlib.cbook.mplDeprecation)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "logger = logging.getLogger()\n",
    "logger.setLevel(logging.DEBUG)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "rcParams.update({'font.size': 14, 'figure.dpi': 300, 'savefig.bbox': 'tight'})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# User inputs\n",
    "\n",
    "## Domain\n",
    "Define the domain of interest (lon_min, lon_max, lat_min, lat_max) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "coordinates = (-6.75, 36.001, 30, 48.)\n",
    "meridians = np.arange(-8., 40., 8.)\n",
    "parallels = np.arange(30., 50., 4.5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We downloaded the product *SEALEVEL_MED_SLA_MAP_L4_REP_OBSERVATIONS_008_029* from [CMEMS](http://marine.copernicus.eu).     \n",
    "It corresponds to *dataset-duacs-rep-medsea-merged-allsat-msla-l4*: a reprocessed product of Sea Level Anomalies (SLA) using all the available satellites"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:root:Data directory: /home/ctroupin/Data/AVISO/Gridded/2014\n"
     ]
    }
   ],
   "source": [
    "datadir = os.path.expanduser(\"~/Data/AVISO/Gridded/2014\")\n",
    "# datadir = os.path.expanduser(\"~/Data/AVISO/Gridded/SEALEVEL_MED_SLA_MAP_L4_NRT_OBSERVATIONS_008_028/2014\")\n",
    "\n",
    "figdir = os.path.expanduser(\"~/Data/AVISO/Gridded/figures/2014\")\n",
    "# figdir = os.path.expanduser(\"~/Data/AVISO/Gridded/figures/SEALEVEL_MED_SLA_MAP_L4_NRT_OBSERVATIONS_008_028/2014\")\n",
    "\n",
    "figdir2 = os.path.expanduser(\"~/Data/AVISO/Gridded/figures/2014/gradients/\")\n",
    "# figdir2 = os.path.expanduser(\"~/Data/AVISO/Gridded/figures/SEALEVEL_MED_SLA_MAP_L4_NRT_OBSERVATIONS_008_028/2014/gradient\")\n",
    "\n",
    "\n",
    "if not os.path.exists(figdir):\n",
    "    os.makedirs(figdir)\n",
    "if not os.path.exists(figdir2):\n",
    "    os.makedirs(figdir2)\n",
    "    \n",
    "logging.info(\"Data directory: {0}\".format(datadir)) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## File list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:root:Working on 365 files\n"
     ]
    }
   ],
   "source": [
    "datafilelist = sorted(glob.glob(os.path.join(datadir, \"dt_med_allsat_msla_h_*.nc\")))\n",
    "# datafilelist = sorted(glob.glob(os.path.join(datadir, \"nrt_med_allsat_msla_h_*\")))\n",
    "logging.info(\"Working on {0} files\".format(len(datafilelist)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Projection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "m = Basemap(projection='merc',\n",
    "            llcrnrlon=coordinates[0], llcrnrlat=coordinates[2],\n",
    "            urcrnrlon=coordinates[1], urcrnrlat=coordinates[3],\n",
    "            lat_ts=0.5 * (coordinates[2] + coordinates[3]), resolution='i')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Loop on files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140101_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140102_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140103_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140104_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140105_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140106_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140107_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140108_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140109_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140110_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140111_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140112_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140113_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140114_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140115_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140116_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140117_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140118_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140119_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140120_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140121_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140122_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140123_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140124_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140125_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140126_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140127_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140128_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140129_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140130_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140131_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140201_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140202_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140203_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140204_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140205_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140206_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140207_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140208_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140209_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140210_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140211_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140212_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140213_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140214_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140215_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140216_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140217_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140218_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140219_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140220_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140221_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140222_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140223_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140224_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140225_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140226_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140227_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140228_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140301_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140302_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140303_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140304_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140305_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140306_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140307_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140308_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140309_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140310_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140311_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140312_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140313_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140314_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140315_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140316_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140317_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140318_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140319_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140320_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140321_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140322_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140323_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140324_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140325_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140326_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140327_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140328_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140329_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140330_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140331_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140401_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140402_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140403_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140404_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140405_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140406_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140407_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140408_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140409_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140410_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140411_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140412_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140413_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140414_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140415_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140416_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140417_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140418_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140419_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140420_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140421_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140422_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140423_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140424_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140425_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140426_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140427_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140428_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140429_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140430_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140501_20140829.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140502_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140503_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140504_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140505_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140506_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140507_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140508_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140509_20141010.nc\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140510_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140511_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140512_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140513_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140514_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140515_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140516_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140517_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140518_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140519_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140520_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140521_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140522_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140523_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140524_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140525_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140526_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140527_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140528_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140529_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140530_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140531_20141010.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140601_20141124.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140602_20141124.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140603_20141124.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140604_20141124.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140605_20141124.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140606_20141124.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140607_20141124.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140608_20141124.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140609_20141124.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140610_20141124.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140611_20141124.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140612_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140613_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140614_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140615_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140616_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140617_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140618_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140619_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140620_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140621_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140622_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140623_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140624_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140625_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140626_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140627_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140628_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140629_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140630_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140701_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140702_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140703_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140704_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140705_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140706_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140707_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140708_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140709_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140710_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140711_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140712_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140713_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140714_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140715_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140716_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140717_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140718_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140719_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140720_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140721_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140722_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140723_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140724_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140725_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140726_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140727_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140728_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140729_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140730_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140731_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140801_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140802_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140803_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140804_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140805_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140806_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140807_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140808_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140809_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140810_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140811_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140812_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140813_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140814_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140815_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140816_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140817_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140818_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140819_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140820_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140821_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140822_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140823_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140824_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140825_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140826_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140827_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140828_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140829_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140830_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140831_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140901_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140902_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140903_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140904_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140905_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140906_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140907_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140908_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140909_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140910_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140911_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140912_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140913_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140914_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140915_20150209.nc\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140916_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140917_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140918_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140919_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140920_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140921_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140922_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140923_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140924_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140925_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140926_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140927_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140928_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140929_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20140930_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141001_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141002_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141003_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141004_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141005_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141006_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141007_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141008_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141009_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141010_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141011_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141012_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141013_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141014_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141015_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141016_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141017_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141018_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141019_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141020_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141021_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141022_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141023_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141024_20150209.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141025_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141026_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141027_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141028_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141029_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141030_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141031_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141101_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141102_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141103_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141104_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141105_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141106_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141107_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141108_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141109_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141110_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141111_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141112_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141113_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141114_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141115_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141116_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141117_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141118_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141119_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141120_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141121_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141122_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141123_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141124_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141125_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141126_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141127_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141128_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141129_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141130_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141201_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141202_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141203_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141204_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141205_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141206_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141207_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141208_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141209_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141210_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141211_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141212_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141213_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141214_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141215_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141216_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141217_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141218_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141219_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141220_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141221_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141222_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141223_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141224_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141225_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141226_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141227_20150513.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141228_20150914.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141229_20150914.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141230_20150914.nc\n",
      "DEBUG:root:Working on dt_med_allsat_msla_h_20141231_20150914.nc\n"
     ]
    }
   ],
   "source": [
    "for datafile in datafilelist:\n",
    "    fname = os.path.basename(datafile)\n",
    "    figname = os.path.join(figdir, fname.split('.')[0])\n",
    "    logging.debug(\"Working on {0}\".format(fname))\n",
    "    \n",
    "    # Read data\n",
    "    SLA = divaaltimetry.AltimetryField().from_aviso_file(datafile)\n",
    "    \n",
    "    # field plot\n",
    "    figtitle = SLA.filetime[0].strftime(\"%Y-%m-%d\")\n",
    "    \n",
    "    SLA.add_to_plot(figname, figtitle, m=m,\n",
    "                    meridians=meridians, parallels=parallels,\n",
    "                    vmin=-0.2, vmax=0.2,\n",
    "                    cmap=plt.cm.RdYlBu_r)\n",
    "    \n",
    "    \n",
    "    # Gradient \n",
    "    fignamegrad = os.path.join(figdir2, \"\".join((\"grad_\", os.path.basename(datafile).split('.')[0])))\n",
    "    figtitle = SLA.filetime[0].strftime(\"%Y-%m-%d\")\n",
    "    SLA.gradients(fignamegrad, figtitle, m=m,\n",
    "                  meridians=meridians, parallels=parallels,\n",
    "                  vmin=-0.05, vmax=0.05,\n",
    "                  cmap=plt.cm.RdYlBu_r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/home/ctroupin/Data/AVISO/Gridded/figures/2014/gradients/'"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "figdir2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Diva-python3.6",
   "language": "python",
   "name": "diva-python3.6"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
